import request from '@/utils/request'

/**
 *  分页查询
 * @param pageNum
 * @param pageSize
 * @param queryRequest
 * @returns {*}
 */
export const getUserList = (pageNum, pageSize, queryRequest) => {
  return request({
    url: `/user/system/sysUser/findUserByPage/${pageNum}/${pageSize}`,
    params: queryRequest,
    method: 'get',
  })
}

/**
 *  添加用户
 * @param sysUser
 * @returns {*}
 */
export const doAddUser = sysUser => {
  return request({
    url: `/user/system/sysUser/addUser`,
    data: sysUser,
    method: 'post',
  })
}

/**
 *  根据id查询用户
 * @param id
 * @returns {*}
 */
export const findUserById = id => {
  return request({
    url: `/user/system/sysUser/findUserById/${id}`,
    method: 'get',
  })
}
/**
 *  修改用户
 * @param sysUser
 * @returns {*}
 */
export const updateUser = sysUser => {
  return request({
    url: `/user/system/sysUser/updateUser`,
    method: 'PUT',
    data: sysUser,
  })
}

/**
 *  删除用户
 * @param id
 * @returns {*}
 */
export const deleteUserById = id => {
  return request({
    url: `/user/system/sysUser/deleteUserById/${id}`,
    method: 'delete',
  })
}

/**
 *  批量删除用户
 * @param ids
 * @returns {*}
 */
export const doBatchDelete = ids => {
  return request({
    url: `/user/system/sysUser/batchDelete`,
    method: 'delete',
    data: ids,
  })
}

/**
 *  批量删除用户
 * @returns {*}
 */
export const findRoles = () => {
  return request({
    url: `/user/system/sysRole/findRoles`,
    method: 'get',
  })
}

/**
 *  批量删除用户
 *  @param id
 * @returns {*}
 */
export const findRolesByUserId = id => {
  return request({
    url: `/user/system/sysUserRole/findRolesByUserId/${id}`,
    method: 'get',
  })
}

/**
 *  分配用户角色
 * @param userId
 * @param roleIds
 * @returns {AxiosPromise}
 */
export const assignUserRole = (userId, roleIds) => {
  return request({
    url: `/user/system/sysUserRole/assignUserRole/${userId}`,
    method: 'POST',
    data: roleIds,
  })
}
